/**
 * This class represents a player's node in the search-tree-structure.
 * It's a kind of information source for the alpahabeta-engine.
 *
 */
package AIEngine;

public class Node {

    private boolean camp;           // represents the topical player
    private long depth;             // specification of the searchdeep
    private long value;             // specification of the value
    private int[] move = new int[4];
    private int[][] board = new int[6][6];
    private int[][] tmpboard = new int[6][6];
    private int turnsLeft;

	/**
     * The default constructor for a node.
     * The commited node is describes the parent node.
     * Therefore the dates of the node are adjusted to the parent (e.g. campe=!camp)
     * To instantiated a rootnode commit NULL
     *
     * @param parent
     * @param field
     */
    public Node(Node parent,int field[][], int turnsLeft) {
        int x,y;
        if (parent != null) {
            camp = !(parent.getCamp());
            depth = parent.getDepth() + 1;
            board = parent.getBoard();
            this.turnsLeft = parent.getTurnsLeft() - 1;
        } else {
            camp = true;
            depth = 0;
            board = new int[6][6] ;
            for (x=0;x<6;x++) {
			for (y=0;y<6;y++) {
                            board[x][y]=field[x][y];
                        }
			this.turnsLeft = turnsLeft;
            }

        }
        value = 0;
    }

    /**
     * Secenod constructor for a node.
     * Allows to creat a node by commiting the root, a move obejkt and a field
     *
     * @param parent <=> root node
     * @param mov is a movebojekt
     * see Move
     * @param field is the corresponding board array
     */
    public Node(Node parent, int[] mov, int[][] field, int turnsLeft) {

        if (parent != null) {
            camp = !(parent.getCamp());
            depth = parent.getDepth() + 1;
            board = field;
            move = mov;
            value=0;
            this.turnsLeft = parent.getTurnsLeft() - 1;
        } else {
            camp = true;
            depth = 0;
            board = new int[6][6];
            this.turnsLeft = turnsLeft;
        }
        value = 0;
    }

    /**
     * Getter for tmpboard
     * @return tmpboard
     */
    public int[][] getTmpboard() {
        return tmpboard;
    }

    /**
     * Setter for tmpboard.
     * @param tmpboard new value of tmpboard
     */
    public void setTmpboard(int[][] tmpboard) {
        this.tmpboard = tmpboard;
    }

    /**
     * Setter for board
     * @param board new value of board
     */
    public void setBoard(int[][] board) {
        this.board = board;
    }

    /**
     * Allows to set a element into a board array.
     *
     * @param site of the player true will set -1, false will set 1
     * @param i x-coordinate for the row
     * @param j y-coordinate for the column
     */
    public void setBoardElement(boolean site, int i, int j) {
        if (site) {
            this.board[i][j] = -1;
        } else {
            this.board[i][j] = 1;
        }
    }

    /**
     * Allows to set a element into the Tmpboard array.
     *
     * @param site of the player true will set -1, false will set 1
     * @param i x-coordinate for the row
     * @param j y-coordinate for the column
     */
    public void setTmpboardElement(boolean site, int i, int j) {
        if (site) {
            this.tmpboard[i][j] = -1;
        } else {
            this.tmpboard[i][j] = 1;
        }
    }

    /**
     * Board getter
     * @return board
     */
    public int[][] getBoard() {
        return board;
    }

    /**
     * Move getter.
     * @return move
     */
    public int[] getMove() {
        return move;
    }

    /**
     * Side getter.
     * @return campe
     */
    public boolean getCamp() {
        return camp;
    }

    /**
     * Side setter.
     * @param camp sets the side to camp
     */
    public void setCamp(boolean camp) {
        this.camp = camp;
    }

    /**
     * Depth getter.
     * @return depth
     */
    public long getDepth() {
        return depth;
    }

    /**
     * Depth setter.
     * @param depth
     */
    public void setDepth(long depth) {
        this.depth = depth;
    }

    /**
     * Value getter.
     * @return value
     */
    public long getValue() {
        return value;
    }

    /**
     * Value setter.
     * @param value
     */
    public void setValue(long value) {
        this.value = value;
    }
    
    /**
     * Turns left getter.
     * @return value
     */
    public int getTurnsLeft() {
		return turnsLeft;
	}

    /**
     * Turns left setter.
     * @param value
     */
	public void setTurnsLeft(int turnsLeft) {
		this.turnsLeft = turnsLeft;
	}
}
